package com.xjrsoft.module.visual.controller;


import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.module.visual.dto.VisualReleaseDto;
import com.xjrsoft.module.visual.dto.VisualReleaseHomeDto;
import com.xjrsoft.module.visual.dto.VisualReleaseListDto;
import com.xjrsoft.module.visual.service.IXjrVisualReleaseService;
import com.xjrsoft.module.visual.vo.VisualReleaseHomeVo;
import com.xjrsoft.module.visual.vo.VisualReleaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 看板发布表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-10
 */
@AllArgsConstructor
@RestController
@RequestMapping("/visual-release")
@Api(value = "/visual-release",tags = "看板发布模块")
public class XjrVisualReleaseController {

    private final IXjrVisualReleaseService visualReleaseService;

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/19
     * @Param:[]
     * @return:com.xjrsoft.common.result.Response
     * @Description:看板发布分页查询
     */
    @GetMapping
    @ApiOperation("看板发布分页查询")
    public Response<PageOutput<VisualReleaseVo>> selectPageList(VisualReleaseListDto dto) {
        return Response.ok(visualReleaseService.selectPageList(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/19
     * @Param:[]
     * @return:com.xjrsoft.common.result.Response
     * @Description:保存看板发布
     */
    @PostMapping
    @ApiOperation("保存看板发布")
    public Response save(@RequestBody VisualReleaseDto dto) {
        return Response.status(visualReleaseService.add(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/19
     * @Param:[]
     * @return:com.xjrsoft.common.result.Response
     * @Description:更新看板发布
     */
    @PutMapping("/{id}")
    @ApiOperation("更新看板发布")
    public Response update(@PathVariable String id, @RequestBody VisualReleaseDto dto) {
        return Response.ok(visualReleaseService.updateVisualRelease(id, dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/19
     * @Param:[]
     * @return:com.xjrsoft.common.result.Response
     * @Description:删除看板发布
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除看板发布")
    public Response delete(@PathVariable String ids) {
        return Response.status(visualReleaseService.removeByIds(Arrays.asList(ids.split(","))));
    }

    @GetMapping("/home")
    @ApiOperation("查询发布到主页的BI看板")
    public Response<PageOutput<VisualReleaseHomeVo>> getReleaseInHomePageList(VisualReleaseHomeDto dto) {
        return Response.ok(visualReleaseService.getReleaseInHomePageList(dto));
    }

    @GetMapping("/all")
    @ApiOperation("查询发布到主页的所有看板")
    public Response getAllReleaseInHome() {
        return Response.ok(visualReleaseService.getAllReleaseInHome());
    }
}
